import java.util.Stack;

public class test {
    public static boolean backspaceCompare(String s, String t) {
        Stack<Character> stack1=new Stack<>();
        Stack<Character> stack2=new Stack<>();
        char[] arry1=s.toCharArray();
        char[] arry2=t.toCharArray();
        for(char x:arry1){
            if(x=='#'&&!stack1.isEmpty()){
                stack1.pop();
            }
            else{
                stack1.push(x);
                if(x=='#'){
                    stack1.pop();
                }
            }
        }
        for(char x:arry2){
            if(x=='#'&&!stack2.isEmpty()){
                stack2.pop();
            }
            else{
                stack2.push(x);
                if(x=='#'){
                    stack2.pop();
                }
            }
        }

        while(!stack1.isEmpty()&&!stack2.isEmpty()){
            char po1=stack1.pop();
            char po2=stack2.pop();
            if(po1!=po2){
                return false;
            }
        }
        if(stack1.isEmpty()&&stack2.isEmpty()){
            return true;
        }

        return false;
    }

    public static void main(String[] args) {
        String a="y#fo##f";
        String b="y#f#o##f";
        if(backspaceCompare(a,b)){
            System.out.println("true");
        }
        else{
            System.out.println("false");
        }
    }
}
